<template>
	<view class="page_content">
		<web-view :src="webUrl"></web-view>
		<!-- <u-icon size="32" :name="isCollect == 0 ? 'thumb-up' : 'thumb-up-fill'" :color="isCollect == 0 ? '#333' : 'red'" @click="handleCollect"></u-icon> -->
	</view>
</template>

<script>
import { favoriteModelAdd, cancelFavorite,isFavorite } from '@/api/common.js'
export default {
	data() {
		return {
			webUrl: '',
			data: {},
			isCollect: 0
		}
	},
	onShareAppMessage() {
		return {
			title: '模型浏览',
			path: '/pages/animation?data=' + JSON.stringify(this.data),
			success() {
				console.log('分享成功');
			},
			fail(err) {
				console.error('分享失败', err);
			}
		};
	},
	onLoad(options) {
		this.data = JSON.parse(options.data)
		uni.setNavigationBarTitle({
			title: this.data.modelName
		})
		if(!this.data.uuid) {
			uni.showToast({
				title: 'uuid不能为空',
				icon: 'none'
			});
			setTimeout(function() {
				uni.navigateBack();
			}, 1000);
			return 
		}
		const token = uni.getStorageSync("App-Token") 
		if(this.data.uploadType == 'gsplat'){
			this.webUrl = 'https://platform.real-infinity.cn/renderer/xcx/b/index.html?id='+this.data.uuid+'&Authorization='+token
		}else {
			this.webUrl = 'https://platform.real-infinity.cn/renderer/xcx/a/index.html?id='+this.data.uuid+'&Authorization='+token
		}
		// isFavorite({buildModelId:this.data.buildModelId}).then(res => {
		// 	this.isCollect = res.data == 0 ? 0 : 1
		// })
	},
	methods: {
		handleCollect() {
			if(this.isCollect == 0) {
				favoriteModelAdd({buildModelId:this.data.buildModelId}).then(res => {
					uni.showToast({
					  icon: 'none',
					  title: '收藏成功'
					})
					this.isCollect = 1
					uni.$emit('handleList');
				})
			}else {
				cancelFavorite({buildModelId: this.data.buildModelId }).then(res => {
					uni.showToast({
						icon: 'none',
						title: '取消收藏'
					})
					uni.$emit('handleList');
					this.isCollect = 0
				})
			}
		}
	}
}
</script>